package com.itheima.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 配置放行
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println("页面放行完成");
        registry.addResourceHandler("/front/css/**")
                .addResourceLocations("classpath:/front/css/");
        registry.addResourceHandler("/front/js/**")
                .addResourceLocations("classpath:/front/js/");
        registry.addResourceHandler("/front/pages/**")
                .addResourceLocations("classpath:/front/pages/");
        registry.addResourceHandler("/front/plugins/**")
                .addResourceLocations("classpath:/front/plugins/");
    }

    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        converter.setObjectMapper(new JacksonObjectMapper());//让我们自定义的映射转化， 覆盖掉原来的json消息转换

        //让新的消息转换器生效，  加入消息转换器集合
        // 0 生效顺序。默认按照集合的索引顺序  0 是最高的
        converters.add(0,converter);
    }
}
